package com.ruoyi.system.waishu;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Slf4j
@Service
public class ApiServiceFactory implements BeanPostProcessor {

    private static final String SPLIT = "-";
    private static final String VERSION = "1.0.0";
    private HashMap<String,ThirdDataService> map;
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof ApiService){
            ApiService annotation = bean.getClass().getAnnotation(ApiService.class);
            map.put(annotation.value()+SPLIT+VERSION, (ThirdDataService) bean);
        }
        return bean;
    }
    public ThirdDataService builder(String v1){
        return map.get(v1+SPLIT+VERSION);
    }
}
